package com.guigu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.*;
import com.guigu.service.GatherInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/gatherInfo/")
public class GatherInfoController {
    @Autowired
    GatherInfoService gatherInfoService;

    //根据采购单id，添加入库表和入库详情表数据，入库表需要审核
    @GetMapping("addGatherInfoandDetailPurchaseInfo.action/{id}")
    public Map addGatherInfoAndDetailPurchaseInfo(@PathVariable Integer id){
        return  gatherInfoService.addGatherInfoAndDetailPurchaseInfo(id);
    }

    //根据采购详情id，获取可以存放的仓库有哪些
    @GetMapping("storableWarehouse.action")
    public com.guigu.service.utils.Page storableWarehouse(PurchaseDetailInfo purchaseDetailInfo,
                                                          @RequestParam(value = "pageno", defaultValue = "1") Integer pageno,
                                                          @RequestParam(value = "pagesize", defaultValue = "5") Integer pagesize){
        return  gatherInfoService.storableWarehouse(purchaseDetailInfo,pageno,pagesize);
    }

    //最终提交
    @GetMapping("changeDetailInfoState.action/{purchaseInfoId}")
    public Map changeGatherInfo(@PathVariable Integer purchaseInfoId){
        return gatherInfoService.changeDetailInfoState(purchaseInfoId);
    }

    //分页及所有
    @GetMapping("queryAll.action")
    public Page<GatherInfo> queryAll(GatherInfo gatherInfo,
                                               @RequestParam(value = "pageno", defaultValue = "1") Integer pageno,
                                               @RequestParam(value = "pagesize", defaultValue = "5") Integer pagesize) {
        return gatherInfoService.queryAll(gatherInfo,pageno,pagesize);
    }

    //审核入库单
    @PutMapping("audit.action")
    public Map audit(@RequestBody GatherInfo gatherInfo){
        return gatherInfoService.audit(gatherInfo);
    }

    @GetMapping("queryAllGatherInfo.action")
    @CrossOrigin
    //曹科 入库申请查询
    public Page queryAllGatherInfo(GatherInfo gatherInfo,
                                   @RequestParam(value = "pageno", defaultValue = "1") Integer pageno,
                                   @RequestParam(value = "pagesize", defaultValue = "5") Integer pagesize){
        return gatherInfoService.queryAllGatherInfo(gatherInfo,pageno,pagesize);
    }

    //根据退货申请表id和仓库名，添加入库表和入库详情表数据并且指定仓库，入库表需要审核
    @GetMapping("addGatherInfoandSalesReturn.action")
    public Map addGatherInfoandSalesReturn(Integer id,Integer warehouseId){
        return  gatherInfoService.addGatherInfoandSalesReturn(id,warehouseId);
    }

    //根据退货表id，获取可以存放的仓库有哪些
    @GetMapping("salesReturnWarehouse.action")
    public com.guigu.service.utils.Page salesReturnWarehouse(ReturnShopInfo returnShopInfo,
                                                             @RequestParam(value = "pageno", defaultValue = "1") Integer pageno,
                                                             @RequestParam(value = "pagesize", defaultValue = "5") Integer pagesiz){
        return  gatherInfoService.salesReturnWarehouse(returnShopInfo,pageno,pagesiz);
    }

}
